<?php

namespace app\admin\service;


class BaseService
{

    /**
     * @return mixed
     */
    public function getError()
    {
        return $this->error;
    }

    /**
     * @param mixed $error
     */
    public function setError($error)
    {
        $this->error = $error;
    }
    
    /**
     * 返回成功的结果
     *
     * @Author tanruizheng
     * @DateTime 2021-07-09
     * @param string $msg
     * @param array $data
     * @param [type] $code
     * @param string $url
     * @return void
     */
    public static function createSuccess($msg = 'success',$data = [], $code = null, $url = ''){
        //默认成功则为200
        if(!$code) {
            $code = 200;
        }
        if (is_array($msg)) {
            $data = $msg;
            $msg = 'success';
        }
        return [
            'status'    => true,
            'data'      => $data,
            'msg'       => $msg ?: 'success',
            'code'      => $code,
            'url'       => $url,
        ];
    }

    /**
     * 返回失败的结果
     *
     * @Author tanruizheng
     * @DateTime 2021-07-09
     * @param string $msg
     * @param array $data
     * @param [type] $code
     * @param string $url
     * @return void
     */
    public static function createFail($msg = 'fail',$data = [], $code = null, $url = ''){
        //默认失败为400
        if(!$code) {
            $code = 400;
        }
        if (is_array($msg)) {
            $data = $msg;
            $msg = 'fail';
        }
        return [
            'status'    => false,
            'data'      => $data,
            'msg'       => $msg ?: 'fail',
            'code'      => $code,
            'url'       => $url,
        ];
    }

     /**
     * 返回列表格式
     *
     * @Author tanruizheng
     * @DateTime 2021-07-09
     * @param string $msg
     * @param array $data
     * @param [type] $code
     * @param string $url
     * @return void
     */
    public static function createList($data = [], $count = 0, $msg = 'ok'){
        if(!$count) {
           $count = count($data);
        }
        return [
            'code'  => 0,
            'msg'   => $msg,
            'count' => $count,
            'data'  => $data,  
        ];
    }
}